package com.legendshop.openportal.sdk.registry;

import com.legendshop.openportal.sdk.cache.DefaultOpenCache;
import com.legendshop.openportal.sdk.cache.OpenCache;
import com.legendshop.openportal.sdk.exception.OpenClientException;

/**
 * @author jzh
 * @version 1.0.0
 * @title OpenCacheRegistry
 * @date 2024/6/18 10:33
 * @description：缓存注册器
 */
public class OpenCacheRegistry {

    private static final OpenCache DEFAULT_CACHE = new DefaultOpenCache();
    private static volatile OpenCache customCache;

    private OpenCacheRegistry() {}

    public static void registerCache(final OpenCache cache) {
        if (cache == null) {
            throw new OpenClientException("customCache cannot be null");
        }
        customCache = cache;
    }

    public static OpenCache getCache() {
        return customCache != null ? customCache : DEFAULT_CACHE;
    }

}
